﻿<!-- _meta 作为公共模版分离出去 -->
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp"/>
	<link rel="Shortcut Icon" href="/admin/imgs/logo.ico"/>
	<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
	<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css"/>
	<title>大会后台</title>
	<style type="text/css">
		/*#detail { width: 500px; min-height: 100px; resize: vertical; }*/
		#ueditor { width: 850px; height: 550px; overflow: auto; }
		#myEditor { width: 800px; height: 450px; }
	</style>

	<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
	<!--<script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>-->
	<script type="text/javascript" src="js/admin.js"></script>
	<script type="text/javascript" charset="utf-8" src="js/focus.js"></script>
	<script type="text/javascript" charset="utf-8" src="./js/editor_api_bd.js"></script>
	<script type="text/javascript">
	</script>
</head>
<body>
<section class="Hui-article-box" style="position:relative;top:0;left:0;">
	<nav class="breadcrumb" style="color:#888;">
		<i class="Hui-iconfont">&#xe67f;</i>
		<a href="main.html" class="maincolor">首页</a>
		<span class="c-gray en">&gt;</span>
		前台
		<span class="c-gray en">&gt;</span>
		学术委员会
		<span class="c-gray en">&gt;</span>
		修改
	</nav>
</section>
<div class="page-container" style="margin:10px 10%;width:50%;position:relative;top:50px;left:0;">
	<div class="row cl" style="margin-bottom:20px;">
		<label class="form-label col-xs-4 col-sm-3">
			标题：
		</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" id="title">
		</div>
	</div>
	<div class="row cl" style="margin-bottom:20px;">
		<label class="form-label col-xs-4 col-sm-3">
			图片上传：
		</label>
		<div class="formControls col-xs-8 col-sm-9">
			<div class="uploader-thum-container">
				<div style="height:5px;"></div>
				<div class="webuploader-pick" style="width:80px;cursor:pointer;position:relative;">重选图片</div>
				<input type="file" id="uploadFile" style="width:105px;height:30px;background:#0088CC;opacity:0;cursor:pointer;position:relative;top:-10px;left:-110px;" onchange="uploadImage()"/>
				<input type="hidden" id="img">
				<img src="" id="viewimg">
			</div>
		</div>
	</div>
	<div class="row cl" style="margin-bottom:20px;">
		<label class="form-label col-xs-4 col-sm-3">
			描述：
		</label>
		<div class="formControls col-xs-8 col-sm-9">
			<!--<textarea class="input-text" autoHeight="true" id="detail"></textarea>-->
			<div id="ueditor">
				<script type="text/plain" id="myEditor">
					<p>这里我可以写一些输入提示</p>
				</script>
			</div>
		</div>
	</div>
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
			<button onClick="save()" class="btn btn-secondary radius" type="button">立即保存</button>
			<button onClick="back()" class="btn btn-default radius" type="button"> &nbsp; 返回 &nbsp; </button>
		</div>
	</div>
</div>

<span id="pop"></span>
</body>
</html>


<script type="text/javascript">
	var id = getParamByUrl('id');
	(function(){
		getOne();
	})();
	//获取图片
	function uploadImage() {
		var img = $("#viewimg"), dataURL, fileObj = $('#uploadFile')[0],
				windowURL = window.URL || window.webkitURL, reader = new FileReader();
		dataURL = windowURL.createObjectURL(fileObj.files[0]); //要显示图片的路径
		img.attr("src", dataURL); //显示图片
		reader.readAsDataURL(fileObj.files[0]); //这一步是关键
		reader.onload = function (e){
			var base64 = e.target.result; //这一步是关键
			$('#img')[0].value = base64;
		}
	}
	//初始化百度编辑器
	var ue = UE.getEditor('myEditor',{
		//这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
		// toolbars:[['FullScreen', 'Source', 'Undo', 'Redo','Bold','test']],
		toolbars: [
			//fullscreen全屏，source源码，undo撤销，redo重做
			['fullscreen', 'source', 'undo', 'redo'],
			//fontsize字体大小，bold加粗，italic斜体，underline下划线，fontborder字符边框，strikethrough删除线，superscript上标，removeformat清除格式，formatmatch格式刷，autotypeset自动排版，blockquote引用，pasteplain纯文本粘贴模式，forecolor字体颜色，backcolor背景色，insertorderedlist有序列表，selectall全选，cleardoc，清空文档，simpleupload单图上传，
			['fontsize','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', 'simpleupload']
		],
		//focus时自动清空初始化时的内容
		autoClearinitialContent: true,
		//关闭字数统计
		wordCount: false,
		//关闭elementPath
		elementPathEnabled: false,
		//默认的编辑区域高度
		initialFrameWidth: 700,
		//默认的编辑区域高度
		initialFrameHeight: 450,
		//更多其他参数，请参考ueditor.config.js中的配置项
		autoHeightEnabled: false, //固定高度
	});
	//获取数据
	function getOne(){
		var formData = {id:id};
		$.ajax({
			type: 'post',
			url: domain+'learn/one',
			data: formData,
			success: function (res) {
				res = JSON.parse(res);
				console.log(res);
				if (res.code!=0) {
					pop({msg:res.msg}); return;
				}
				var d = res.data;
				$('#title')[0].value = d.title;
				$('#viewimg').attr('src', d.img);
				setTimeout(function(){
					ue.setContent(d.detail);
				},2000);
			},
			error: function () {
				console.log('网络错误');
			}
		});
	}
	//保存
	function save(){
		var title = $('#title').val();
//		var detail = $('#detail').val();
		var img = $('#img').val();
		var detail = ue.getContent();
		if (title==0) { pop({msg:'没有填写主题'}); return }
		if (detail=='') { pop({msg:'没有填写内容'}); return }
//		if (img=='') { pop({msg:'图片没有'}); return }
		var formData = {
				id: id, title: title, detail: detail, img: img,
		};
		$.ajax({
			type: 'post',
			url: domain+'learn/modify',
			data: formData,
			success: function (res) {
				res = JSON.parse(res);
				console.log(res);
				if (res.code!=0) {
					pop({msg:res.msg}); return;
				}
				pop({msg:'成功'});
				setTimeout(function(){
					window.location.href = 'learn.html';
				},1000);
			},
			error: function () {
				console.log('网络错误');
			}
		});
	}
	function back(){
		window.location.href = 'learn.html';
	}
</script>